Page({
  data: {
    value: '', fileList: [],name:'',phone:"",admin:'',password:'',list:[],radio:1,fileList1:[],fileList2:[],phoneflag:false,
    url2:'',url3:'',url4:'',imgurl:'',statu:'',remark:''
  },

  onChange(event) {
    // event.detail 为当前输入的值
    console.log(event.detail);
  },
  afterRead(event) {
    const { file } = event.detail;
    console.log(file);
    const that=this
      
    
    
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      
      url: 'https://zujieba.com/index/upload/upload.html', // 仅为示例，非真实的接口地址
      filePath: file.path,
      name:'file',
      
      success(res) {
        
        const res1=JSON.parse(res.data).name
        const array=[]
        array.push(res1)
        that.setData({
          list:array,
          url2:res1
        })
        
        
        
        console.log(res1);
        const url1="https://zujieba.com/file_index/"+res1
        
        console.log(url1);
        
        const fileList=[]
        const object={}
        object.url=url1
        object.name=2
        object.deletable=true
        
       fileList.push(object) 
        that.setData({ fileList });
      }
      
    });
  },
  afterRead1(event) {
    const { file } = event.detail;
    console.log(file);
    const that=this
      
    
    
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      
      url: 'https://zujieba.com/index/upload/upload.html', // 仅为示例，非真实的接口地址
      filePath: file.path,
      name:'file',
      
      success(res) {
        
        const res1=JSON.parse(res.data).name
        const array=[]
        array.push(res1)
        that.setData({
          list:array,
          url3:res1
        })
        
        
        
        console.log(res1);
        const url1="https://zujieba.com/file_index/"+res1
        
        console.log(url1);
        
        const fileList=[]
        const object={}
        object.url=url1
        object.name=2
        object.deletable=true
        
       fileList.push(object) 
        that.setData({ fileList1:fileList });
      }
      
    });
  },
  afterRead2(event) {
    const { file } = event.detail;
    console.log(file);
    const that=this
      
    
    
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      
      url: 'https://zujieba.com/index/upload/upload.html', // 仅为示例，非真实的接口地址
      filePath: file.path,
      name:'file',
      
      success(res) {
        
        const res1=JSON.parse(res.data).name
        const array=[]
        array.push(res1)
        that.setData({
          list:array,
          url4:res1
        })
        
        
        
        console.log(res1);
        const url1="https://zujieba.com/file_index/"+res1
        
        console.log(url1);
        
        const fileList = [] 
        const object={}
        object.url=url1
        object.name=2
        object.deletable=true
        
       fileList.push(object) 
        that.setData({ fileList2:fileList });
      }
      
    });
  },
  deleteclick(e){
  const index=  e.detail.index
  const list=this.data.fileList
      list.splice(index,1)
     this.setData({
       fileList:list
     })
         
       
  },
  deleteclick1(e){
    const index=  e.detail.index
    const list=this.data.fileList1
        list.splice(index,1)
       this.setData({
         fileList1:list
       })
           
         
    }, deleteclick2(e){
      const index=  e.detail.index
      const list=this.data.fileList2
          list.splice(index,1)
         this.setData({
           fileList2:list
         })
             
           
      },
  //获取用户店家或共享商
  onChange1(event) {
    console.log(event.detail);
    
    this.setData({
      radio: event.detail,
    });
  },
  //获取用户真实姓名
  change1(e){
    if(e.detail.value==''){
      wx.showToast({
        title: '不能为空',
      })
    }
  this.setData({
    name:e.detail.value
  })
    
  },
  //获取用户的手机号
  change2(e){
    if(e.detail.value==''){
      wx.showToast({
        title: '不能为空',
      })
    }
    this.setData({
      phone:e.detail.value
    })
   let phoneflag= this.checkMobile(e.detail.value)
   this.setData({phoneflag})
  },
  //获取用户输入的后台账号
  change3(e){
    if(e.detail.value==''){
      wx.showToast({
        title: '不能为空',
      })
    }
    this.setData({
      admin:e.detail.value
    })
  },
  //获取用户输入的后台密码
  change4(e){
    if(e.detail.value==''){
      wx.showToast({
        title: '不能为空',
      })
    }
    this.setData({
      password:e.detail.value
    })
  },
  //提交实名认证
    submitauthen(){
      
      
      if(this.data.name==''||this.data.phone==''||this.data.admin==''||this.data.password==''||this.data.fileList.length==0||this.data.fileList1.length==0||
      this.data.fileList2.length==0){
        return wx.showToast({
          title: '请填写完整',
        })
    }
      const uid=wx.getStorageSync('uid')
      const list=this.data.list
      const idcard_qian=this.data.url2
      const idcard_hou=this.data.url3
      const bl=this.data.url4
      const realname=this.data.name
      const admin=this.data.admin
      const password=this.data.password
      const phone=this.data.phone
      const type=parseInt(this.data.radio)+1
      console.log(type);
      const time=new Date().getTime()
      console.log(time);
      const params={uid,idcard_qian,idcard_hou,realname,phone,bl,admin,password,type}
      
      wx.request({
        url: 'https://zujieba.com/Api/ex/ex',
        data:params,
        success:(res)=>{
          if(res.data.success==1){
            
            wx.showToast({
              title: res.data.tips,
              duration:2000
            })
            setTimeout(()=>{
              wx.navigateBack({
                complete: (res) => {},
              })
            },1000)
          }else{
            wx.showToast({
              title:res.data.tips,
              icon:'none'
            })
          }
            
           
        }
      })
      

    },
    //切换商家  共享商
     toggle(e){
       console.log(e.currentTarget.dataset.radio);
       this.setData({
         radio:e.currentTarget.dataset.radio
       })
         
     },
     checkMobile(e){
    
      if(!(/^1[345789][0-9]\d{4,8}$/.test(e))){
        
          
          return false;
      }
      else{
        return true
      }
  },
  checkMobile1(e){
    
    if(!(/^1[345789][0-9]\d{4,8}$/.test(e))){
         wx.showToast({
           title: '手机输入不正确',
           icon:'none'
           
         })
        
        return false;
    }
    else{
      return true
    }
},
  getimage(){
      wx.request({
        url: 'https://zujieba.com/Api/ex/ex_list.html',
        data:{uid:wx.getStorageSync('uid')},
        method:'POST',
        success:(res)=>{
          console.log(res);
          if(res.data.success==1){
            
            this.setData({
           imgurl:res.data.data.img,
           statu:res.data.data.ex,
           remark:res.data.data.remark
            })
          }else{
            this.setData({
              imgurl:''
            })
          }
          
        }
      })
  },
  onLoad(){
    this.getimage()
  },
  backshenqing(){
     this.setData({
       imgurl:''
     })
  },
  change8(e){
   this.checkMobile1(e.detail.value)
  }
  
});